# Definition for a binary tree node.
# class TreeNode:
#     def __init__(self, x):
#         self.val = x
#         self.left = None
#         self.right = None

class Solution:
    def isSymmetric(self, root: TreeNode) -> bool:
        return self.check(root, root)

    def check(self, p, q):
      # 递归
        if not p and not q:
          # 是否全为空
            return True
        if not p or not q:
            return False
        if p.val != q.val:
            return False
            # 迭代检查左子树和右子树
        return self.check(p.left, q.right) and self.check(q.left, p.right)
